﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Jarvis.Sensors
{
    class IESensor : Sensor
    {
        public IESensor()
            : base(1000)
        {
            this.name = "Internet Explorer Sensor";
        }

        public override void Sense(Object stateInfo)
        {
            List<object> explorer = new List<object>();
            List<object> iexplore = new List<object>();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                string filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    if (!iexplore.Contains(ie.LocationURL))
                        iexplore.Add(ie.LocationURL);
                }

                if (filename.Equals("explorer"))
                {
                    if (!explorer.Contains(ie.LocationURL))
                        explorer.Add(ie.LocationURL);
                }
            }

            Sensor s = new Sensor("Internet Explorer Sites");

            if(iexplore.Count > 0)
                s.log(iexplore);
            else
                s.log(null);

            s = new Sensor("Explorer Open Paths");

            if (explorer.Count > 0)
                s.log(explorer);
            else
                s.log(null);
        }
    }
}
